home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1987 March / Ahoy_Magazine_87-03_1987_Double_L_Side_B.d64 / edit random.txt < prev    next >
Text File  |  2022-10-26  |  4KB  |  139 lines

  1. EDIT RANDOM FILES
  2.  
  3. by Richard Bain
  4.  
  5. Edit'wheel'data was written as a
  6. companion program to the
  7. wheel'of'fortune game. With a few
  8. small changes, it can be used to edit
  9. other random files with one string
  10. per record.
  11.  
  12. When RUN, it first asks for a
  13. filename. The default prompt,
  14. ran.wheel, is the file used with the
  15. wheel'of'fortune game (see page 56).
  16. The file is then opened:
  17.  
  18. open file 2,filename$+",r",random 41
  19.  
  20. The desired file may not be on the
  21. disk because the wrong disk is in the
  22. drive or the filename was typed
  23. incorrectly. Normally, when COMAL
  24. tries to OPEN a RANDOM file that is
  25. not on the disk, it will create a new
  26. file entry. This is often
  27. undesirable. It is important to check
  28. if the file exists before trying to
  29. open the file, or include +",r". Then
  30. the disk drive will respond with a
  31. file not found error rather than
  32. create a new file entry. This is a
  33. faster method to open an existing
  34. file because the file is only opened
  35. once, not twice as with the
  36. file'exists method. A second
  37. advantage to this method is that the
  38. disk drive will give a file type
  39. mismatch error if the file is on the
  40. disk, but is not a RANDOM file. A
  41. disadvantage is that it is not
  42. transportable to other versions of
  43. COMAL.
  44.  
  45. Random 41 specifies that the file
  46. record length is 41 bytes. This
  47. allows for 39 characters plus 2 bytes
  48. for the character count as used by
  49. ran.wheel. Other files may need a
  50. different record length. The maximum
  51. possible length is 254.
  52.  
  53. Edit'wheel'data then reads in the
  54. entire file. The file contains a
  55. special format to make this easy. The
  56. first record in the file contains,
  57. max'used, the number of the last
  58. valid record. Once max'used is
  59. determined, records 2 through
  60. max'used can safely be READ. The
  61. program must keep track of the number
  62. of records and WRITE it to the first
  63. record prior to closing the file.
  64. This can serve as a useful standard
  65. for all RANDOM files.
  66.  
  67. The program then asks if you want to
  68. edit the data. This option lets you
  69. change any existing record. The
  70. editing process is easy. The old
  71. entry is printed on the screen and
  72. the cursor is placed on the first
  73. character. Press <RETURN> to keep it
  74. unchanged, or type in the changes you
  75. desire. Note that strings are limited
  76. to 39 characters.
  77.  
  78. After you are finished editing the
  79. data, you have the option of adding
  80. more data (up to 100 records). Type
  81. in the names and phrases you want.
  82. When you have entered all the data,
  83. hit <RETURN> on a blank line to tell
  84. the computer you are finished.
  85.  
  86. Next, you will be asked if you want
  87. any more changes. I recommend you say
  88. yes. This will let you edit the data
  89. again. Even if you think it is right,
  90. this option lets know before it is
  91. saved.
  92.  
  93. When the data is the way you like it,
  94. you will be asked if you want to save
  95. it. All changes have been made in
  96. computer memory only, so you almost
  97. certainly will want to save it back
  98. to the disk. The default filename is
  99. the one specified at the start of the
  100. program, but can be changed. If you
  101. specify a filename that is not on the
  102. disk, a new file will be created.
  103. [Note: it is possible to swap disks
  104. during the program, so this option
  105. can be used to copy the file from one
  106. disk to another. This may be
  107. important for those of you who don't
  108. have a RANDOM file copy program.] The
  109. records are written to the file in
  110. reverse order. When creating a new
  111. RANDOM file, or appending to an old
  112. one, it is important to WRITE the
  113. last record before the others. Then
  114. the file only needs to allocate new
  115. records once instead of allocating
  116. each record as it is used.
  117.  
  118. Random File Problems
  119.  
  120. It seems that if you PRINT FILE a
  121. number to a RANDOM file in COMAL
  122. 0.14, the record entry will start
  123. with CHR$(13) and then be padded with
  124. CHR$(0)s. In COMAL 2.0, the number is
  125. placed in the record, but the rest of
  126. the record is still padded with
  127. CHR$(0)s, overwriting anything which
  128. may have been there before. The
  129. problems seem to disappear when using
  130. READ FILE and WRITE FILE.
  131.  
  132. The 1541 has known bugs writing to
  133. RANDOM files. I try to avoid them by
  134. reading back each record right after
  135. it is written. This seems to solve
  136. the problem. If it doesn't, at least
  137. the program stops when the error
  138. occurs.
  139.